<?php
/**
 * 微信
 * @author xjq
 * 2018年11月09日
 */
class Pay extends MY_Controller
{
	function __construct()
    {
        parent::__construct();
        //加载 微信支付 接口模型
        $this->load->model('WxPay_model','wxpay');
        $this->load->model('Weixin_model','wx');
    }


    function index(){
        $backUrl=base_url().'WxPay/backChange';// 支付回调
        $finalUrl=base_url().'WxPay/finishPay';// 支付完成后的跳转地址
        $orderInfo=array(
                'desc' => '测试商品',
                'ordersn' => date('YmdHis').rand(1000,9999),
                'openid' => isset($_SESSION['userInfo']['openid'])?$_SESSION['userInfo']['openid']:'',
            );
        $res=$this->wxpay->publicAccountPay($backUrl, $orderInfo);
        // print_r($res);exit;

        $payJsp=$this->wxpay->getPayJsp($res);
        $data = array(
            'payJsp'=>json_encode($payJsp),
            'finalUrl'=>$finalUrl,//付款后 跳转地址
        );
        $this->load->view('pay',$data);
    }

    function finishPay(){
        echo '支付成功！';
    }

    function backChange(){
        echo "SUCCESS";
    }

}